{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "import re\n",
    "def refind(line, regular):\n",
    "    msg = re.search(regular, line)\n",
    "    if msg!=None:\n",
    "        msg = msg.group()\n",
    "    else:\n",
    "        msg=\"0.0\"\n",
    "    return msg.split(\":\")[-1]\n",
    "f = open('dumped_pack.json', 'r')\n",
    "content = f.read()\n",
    "datas = json.loads(content)\n",
    "avg_delays = []\n",
    "max_delays = []\n",
    "for data in datas:\n",
    "    if datas[data]:\n",
    "        env_log = datas[data][\"run_log\"][\"env_log\"]\n",
    "        avg_delay = refind(env_log, \"avg_delay:-?\\ *[0-9]+\\.?[0-9]*(?:[Ee]\\ *-?\\ *[0-9]+)?\")\n",
    "        fps = refind(env_log, \"fps:-?\\ *[0-9]+\\.?[0-9]*(?:[Ee]\\ *-?\\ *[0-9]+)?\")\n",
    "        mem = refind(env_log, \"mem:-?\\ *[0-9]+\\.?[0-9]*(?:[Ee]\\ *-?\\ *[0-9]+)?\")\n",
    "        avg_postprocess_time = refind(env_log, \"avg_postprocess_time:-?\\ *[0-9]+\\.?[0-9]*(?:[Ee]\\ *-?\\ *[0-9]+)?\")\n",
    "        max_delay = refind(env_log, \"max_delay:-?\\ *[0-9]+\\.?[0-9]*(?:[Ee]\\ *-?\\ *[0-9]+)?\")\n",
    "        avg_delays.append(float(avg_delay))\n",
    "        max_delays.append(float(max_delay))\n",
    "#         print(avg_delay, fps, mem, avg_postprocess_time, max_delay)\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(30.366666666666667, 41.461906666666664)"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "np.array(avg_delays).mean(),np.array(max_delays).mean()*0.997"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
